package com.woniuxy.service.impl;

import com.github.pagehelper.PageInfo;
import com.woniuxy.mapper.PileMapper;
import com.woniuxy.service.PileService;
import com.woniuxy.util.PageHelperUtil;
import com.woniuxy.util.PageParam;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.woniuxy.entity.dto.stationPile.PileDisplayDTO;
import com.woniuxy.entity.dto.stationPile.PileSimpleDTO;

@Service
@AllArgsConstructor
public class PileServiceImpl implements PileService {
    private PileMapper pileMapper;
    private PageHelperUtil pageHelperUtil;
    @Override
    public PageInfo<?> queryAll(PageParam<?> pageParam) {
        return pageHelperUtil.getPageInfo(pageParam, pileMapper::queryAll, PileDisplayDTO::new);
    }

    @Override
    public PageInfo<PileSimpleDTO> queryByStationId(PageParam<Long> pageParam) {
        return pageHelperUtil.getPageInfo(pageParam, pileMapper::queryByStationIdWithBinding, PileSimpleDTO::new);
    }

    @Override
    public void cancelRelation(Long pileId) {
        pileMapper.cancelRelationByPileId(pileId);
    }

    @Override
    public PageInfo<PileSimpleDTO> queryUnrelatedByStationId(PageParam<Long> pageParam) {
        return pageHelperUtil.getPageInfo(pageParam, pileMapper::queryByStationIdWithUnbinding, PileSimpleDTO::new);
    }

    @Override
    public void addRelation(Long pileId) {
        pileMapper.addRelationByPileId(pileId);
    }
}
